package com.jwell.panprovider.ui.adapter

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.jwell.panprovider.R
import kotlinx.android.synthetic.main.item_choose_stringlayout.view.*

/**
 * Created by 76577 on 2018/6/13.
 * 选择string适配器
 */
class ChooseStringAdapter constructor(list: List<String>) : RecyclerView.Adapter<ChooseStringAdapter.ViewHolder>() {
    private var list = list
    private var onclickListener: OnclickListener? = null
    override fun getItemCount(): Int {
        return list.size
    }

    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent?.context).inflate(R.layout.item_choose_stringlayout, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        with(holder.itemView) {
            text_string.text = list[position]
            holder.itemView.setOnClickListener {
                onclickListener?.Onclick(position)
            }
        }
    }

    interface OnclickListener {
        fun Onclick(position: Int)
    }

    fun setOnclickListener(onclickListener: OnclickListener) {
        this.onclickListener = onclickListener
    }

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
}